﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GuiAndDb
{
    public partial class ProductDetailsForm : Form
    {
        public Product Product { get; set; }

        public ProductDetailsForm()
        {
            InitializeComponent();

            TextBoxHelper.InitHelp(textBox1, "Enter barcode");
            TextBoxHelper.InitHelp(textBox2, "Enter name of product");
            TextBoxHelper.InitHelp(textBox3, "Enter price.Use dot (.) as separator");
            TextBoxHelper.InitHelp(textBox4, "Enter quantity.Use dot (.) as separator");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Product.barCode == null)
            {
                ProductDB db = new ProductDB();
                Product.barCode = db.GenerateBarCode(Convert.ToInt16(comboBox2.SelectedItem));
            }
            else
            {
                Product.barCode = textBox1.Text;
            }
            Product.name = textBox2.Text;
            Product.price = Convert.ToInt16(textBox3.Text);
            Product.quantity = Convert.ToInt16(textBox4.Text);
            Product.expirationDate = dateTimePicker1.Value;
            Product.unitOfMeasure = comboBox1.SelectedItem.ToString();
            Product.department = Convert.ToInt16(comboBox2.SelectedItem);
           }

        private void Form2_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;

            if (Product != null)
            {
                textBox1.Text = Product.barCode;
                textBox2.Text = Product.name;
                textBox3.Text = Product.price.ToString();
                textBox4.Text = Product.quantity.ToString();
                dateTimePicker1.Value = Product.expirationDate;
                comboBox1.SelectedItem = Product.unitOfMeasure;
                comboBox2.SelectedItem = Product.department.ToString();
            }

            else
            {
                Product = new Product();
            }
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            
        }
    }
}
